/*
FieldEntity.cpp
Field Entitity Implementatoin file
Zach Agudelo, Andi Cescolini, Sam Tarin

Drawing and updating functionality for individual players is here
Entities are contained in Filed using compsition
*/

#include "FieldEntity.h"
#include "FieldAnimation.h"
 
std::vector<FieldEntity*> FieldEntity::EntityList;
//initialize
FieldEntity::FieldEntity() {
    Surf_Entity = NULL;
 
    X = Y = 10;
 
    Width = Height = 0;
 
    AnimState = 0; //What player row from bmp
    
    Xbmp=Ybmp=0;
    
}
 
FieldEntity::~FieldEntity() {
}
//initial setup
bool FieldEntity::OnLoad(char* File, int Width, int Height, int MaxFrames, float X, float Y, int AnimState, int status) { //changed
    if((Surf_Entity = FieldSurface::OnLoad(File)) == NULL) {
        return false;
    }

	FieldSurface::Transparent(Surf_Entity, 255, 255, 255);
 
	 //set inputs to all values
    this->Width = Width;
    this->Height = Height;
    
    this->X = X;
    this->Y = Y;
    
    
    this->AnimState = AnimState;
    this->MaxFrames = MaxFrames;
    
    Anim_Control.MaxFrames = MaxFrames;
 
    xInitial = X;
    yInitial = Y;
    
    this->status = status;  //0= other, 1 = offense, 2 =defense (chase ball), 4= first WR, 5= second WR, 6= RB, 7= left corner, 8= right corner, 9= safety 
    
    resetX=X;
    resetY=Y;
    
    return true;
}
//animates each player
void FieldEntity::OnLoop() {
    Anim_Control.OnAnimate();
   
}
//draws to screen
void FieldEntity::OnRender(SDL_Surface* Surf_Display) {
    if(Surf_Entity == NULL || Surf_Display == NULL) return;
 
    FieldSurface::OnDraw(Surf_Display, Surf_Entity, (int)X, (int)Y, Anim_Control.GetCurrentFrame() * Width, (int)AnimState * Height, Width, Height);
    
 //CLAUSE FOR THE FIELD   
   // if (Width > 500){

       // FieldSurface::OnDraw(Surf_Display, Surf_Entity, (int)X, (int)Y, Anim_Control.GetCurrentFrame() *1, AnimState*1, Width, Height);
   // }
}
//free all memory
void FieldEntity::OnCleanup() {
    if(Surf_Entity) {
        SDL_FreeSurface(Surf_Entity);
    }
 
    Surf_Entity = NULL;
}
//sets to last down position
void FieldEntity::setOriginal(float deltaY)
{
    X=resetX;
    Y=resetY+deltaY;
    xInitial=X;
    yInitial=Y;
}
//sets to game starting position
void FieldEntity::setPrevious(){
   X=xInitial;
   Y=yInitial;
}


